package vn.allmobile.newsreader.adapters;

import java.util.List;

import vn.allmobile.newsreader.R;
import vn.allmobile.newsreader.utils.ImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class NewsAdapter extends BaseAdapter {

	private List<NewsItem> mListNews;
	private ImageLoader mImageLoader;
	private int mStartViewIndex;
	private Context context;

	@SuppressWarnings("unchecked")
	public NewsAdapter(Context context, List<NewsItem> listNews,
			int startViewIndex) {
		// this.mListNews = (ArrayList<ItemOnList>) listNews;
		this.mImageLoader = new ImageLoader(context);
		this.context = context;
		this.mListNews = listNews;
		this.mStartViewIndex = startViewIndex;
	}

	@Override
	public int getCount() {
		return 6;
		// return this.mListNews.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return this.mListNews.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View mView = convertView;
		if (convertView == null) {
			if (this.mStartViewIndex * this.getCount() + position >= this.mListNews
					.size()) {
				return new View(context);
			}
			LayoutInflater inflater = (LayoutInflater) parent.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mView = inflater.inflate(R.layout.news_item,
					null);
			TextView mTitleTextView = (TextView) mView
					.findViewById(R.id.txtTitle);
			mTitleTextView.setText(this.mListNews.get(
					this.mStartViewIndex * this.getCount() + position)
					.getTitle());
		}

		return mView;
	}

	public int getmStartViewIndex() {
		return mStartViewIndex;
	}

	public void setmStartViewIndex(int mStartViewIndex) {
		this.mStartViewIndex = mStartViewIndex;
	}

}
